package mo.leetcode_hot;

import java.util.Arrays;

public class L34 {

    public int[] searchRange(int[] nums, int target) {
        int first = -1, second = -1;
        int left = 0, right = nums.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        if (right == nums.length || nums[right] != target) {
            return new int[]{first, second};
        }
        first = right;
        right = nums.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (nums[mid] <= target) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        second = right - 1;
        return new int[]{first, second};
    }



    public static void main(String[] args) {
        L34 test = new L34();
        System.out.println(Arrays.toString(test.searchRange(new int[]{3, 3, 3}, 3)));
    }

}
